<?php
$this->pageTitle=Yii::app()->name . ' - Договор рассрочки';
$this->breadcrumbs=array(
	'Поиск'=>Yii::app()->createUrl('clients/search'),
	'Карточка клиента'=>Yii::app()->createUrl('clients/view',array('id'=>$Credit->client_id)),
	'Договор рассрочки'
);
?>

<fieldset>
	<legend>
		<div class="pull-left">Договор рассрочки №<?=$Credit->id?></div>
		<?php if($Credit->status == Credits::STATUS_SUCCESS or $Credit->status == Credits::STATUS_CLOSED):?>
		<div class="pull-right">
			<?php $this->widget('bootstrap.widgets.TbButton', array(
				'buttonType'=>'link',
				'url'=>Yii::app()->createUrl('credits/PrintContract',array('id'=>$Credit->id)),
				'type'=>'info',
				'label'=>'<i class="icon-print icon-white"></i> Печать',
				'encodeLabel'=>false,
				'htmlOptions'=>array('target'=>'_blank')
			)); ?>
		</div>
		<?php endif;?>
		<div class="clearfix"></div>
	</legend>
	<div id="credit-block">
		<dl class="dl-horizontal">
			<dt>Клиент</dt>
			<dd><?=CHtml::link($Credit->client->surname.' '.$Credit->client->name.' '.$Credit->client->patronymic,Yii::app()->createUrl('clients/view',array('id'=>$Credit->client->id)))?></dd>

			<dt><?=$Credit->getAttributeLabel('created_at')?></dt>
			<dd><?=date('d.m.Y', strtotime($Credit->created_at))?></dd>

			<dt><?=$Credit->getAttributeLabel('receipt_date')?></dt>
			<dd><?=$Credit->receipt_date?date('d.m.Y',strtotime($Credit->receipt_date)):'-'?></dd>

			<dt><?=$Credit->getAttributeLabel('product_name')?></dt>
			<dd><?=$Credit->product_name?></dd>

			<dt><?=$Credit->getAttributeLabel('sum')?></dt>
			<dd><?=$Credit->sum?> руб.</dd>

			<?php if($Credit->status==Credits::STATUS_SUCCESS or $Credit->status==Credits::STATUS_CLOSED):?>
			<dt>Выплачено</dt>
			<dd><?=$Credit->repaymentsSum?> руб.</dd>

			<dt>Осталось выплатить</dt>
			<dd><?=$Credit->sum - $Credit->repaymentsSum?> руб.</dd>
			<?php endif;?>

			<dt><?=$Credit->getAttributeLabel('duration')?></dt>
			<dd><?=$Credit->duration;?></dd>

			<?php if($Credit->status==Credits::STATUS_SUCCESS):?>
			<dt>Осталось (дней)</dt>
			<dd><?=$Credit->getEndDays()?:'<span class="label label-important">Просрочен</span>'?></dd>
			<?php endif;?>

			<dt><?=$Credit->getAttributeLabel('status')?></dt>
			<dd><?=Credits::getStatusName($Credit->status);?></dd>

			<dt><?=$Credit->getAttributeLabel('close_date')?></dt>
			<dd><?=$Credit->close_date?date('d.m.Y',strtotime($Credit->close_date)):'-'?></dd>
		</dl>
	</div>
</fieldset>


<?php if($Credit->status == Credits::STATUS_SUCCESS or $Credit->status == Credits::STATUS_CLOSED):?>
<fieldset>
	<legend>Список платежей по договору</legend>

	<?php $this->widget('bootstrap.widgets.TbGridView', array(
		'type'=>'condensed',
		'dataProvider'=> $Credit->getRepayments(),
		'enablePagination'=>true,
		'template'=>"{items}{pager}",
		'emptyText'=>'По данному договору еще не было платежей',
		'showTableOnEmpty'=>false,
		'htmlOptions'=>array('style'=>'padding:0;'),
		'columns'=>array(
			'sum',
			array(
				'name'=>'created_at',
				'value'=>'date("d.m.Y H:i:s",strtotime($data->created_at))'
			)
		),
	)); ?>
	<?php if($Credit->status != Credits::STATUS_CLOSED):?>
	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'link',
			'url'=>Yii::app()->createUrl('repayments/add',array('credit_id'=>$Credit->id)),
			'type'=>'success',
			'label'=>'Погашение рассрочки',
		)); ?>
	</div>
	<?php endif;?>
</fieldset>
<?php endif;?>
